package com.eliza.databindadv.recycleView

import android.util.Log
import android.view.LayoutInflater
import android.view.TextureView
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.eliza.databindadv.R
import com.eliza.databindadv.databinding.ActivityBindRecycleItemBinding
import com.eliza.databindadv.model.User


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 3/26/22
 * @Software: Android Studio
 */
class RecycleBindAdapter(var userList: List<User>) :
    RecyclerView.Adapter<RecycleBindAdapter.MyViewHolder>() {


    inner class MyViewHolder : RecyclerView.ViewHolder {

        lateinit var itemBind: ActivityBindRecycleItemBinding

        constructor(itemBind: ActivityBindRecycleItemBinding) : super(itemBind.root) {
            this.itemBind = itemBind
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val dbv = DataBindingUtil.inflate<ActivityBindRecycleItemBinding>(
            LayoutInflater.from(parent.context),
            R.layout.activity_bind_recycle_item, parent, false
        )

        return MyViewHolder(dbv)

    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        holder.itemBind.user = userList[position]
    }

    override fun getItemCount() = userList.size
}